<template>
    <view>
        <view class="list">
            <u-list
                @scrolltolower="scrolltolower"
            >
                <u-list-item
                    v-for="(item, index) in indexList"
                    :key="index"
                >
                    <view class="item" @click="goDetail(item)">
                        <text class="t1">{{ item.name }}</text>
                        <image src="@/static/my-6.png" v-if="item.sign_no_type == 2"></image>
                        <image src="@/static/my-7.png" v-else></image>
                    </view>
                
                </u-list-item>
            </u-list>
            
        </view>
        
        <u-popup :show="qrShow" mode='center'
            :round="10"
            closeable
            :safe-area-inset-bottom='false'
            @close="onClose"
        >
            <view class="my-qrcode">
                <view class="tit">{{qr_title}}</view>
                <view class="image">
                    <image :src='qrcode'></image>
                </view>
            </view>
        </u-popup>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                qrShow: false,
                qrcode: '',
                indexList: [],
                qr_title:''
            }
        },
        onLoad() {
            this.loadmore()
        },
        methods: {
            scrolltolower() {
                this.loadmore()
            },
            loadmore() {
                let that = this
                that.$API.getTaskList().then(res => {
                    res.data.forEach(v => {
                        that.indexList.push(v)
                    });
                }).catch(err => {
                    console.log('err', err)
                })
            },
            getScanCode(item){
                let that = this
                uni.scanCode({
                    onlyFromCamera: true,
                    success: function (res) {
                        console.log('条码类型：' + res.scanType);
                        console.log('条码内容：' + res.result);
                        that.$API.getTaskUser({id: item.id, code: res.result}).then(res => {
                                console.log(res)
                                // 根据扫码结果继续展示
                                uni.showModal({
                                    title: '',
                                    content: res.data.nickname + '签到成功',
                                    cancelText:"完成",
                                    confirmText:'继续签到',
                                    success: function (res) {
                                        if (res.confirm) {
                                            console.log('用户点击继续签到');
                                            that.getScanCode(item);
                                        } else if (res.cancel) {
                                            console.log('用户点击完成');
                                        }
                                    }
                                });
                        })
                    }
                });
            },
            goDetail(item) {
                let that = this
                if (item.sign_no_type == 2) {
                    that.getScanCode(item)
                } else {
										this.qr_title = item.name
                    this.qrcode = item.qrcode_text
                    this.qrShow = true
                }
            },
						onClose(){
							this.qrShow = false
						}
        }
    }
</script>

<style lang="scss">
.item {
    width: 630rpx;
    height: 108rpx;
    background: #FFFFFF;
    margin: 12rpx auto;
    padding: 0 36rpx;
    display: flex;
    flex-direction: row;
    align-items: center;
    .t1 {
        width: 592rpx;
        height: 48rpx;
        line-height: 48rpx;
        color: #303133;
        font-size: 32rpx;
        overflow: hidden;
				font-weight: 500;
        text-overflow: ellipsis;
        display:-webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient:vertical;
    }
    image {
        width: 48rpx;
        height: 48rpx;
    }
}
.my-qrcode {
    width: 614rpx;
    height: 652rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    .tit {
        height: 56rpx;
        font-size: 32rpx;
        font-weight: 500;
        color: #000000;
        line-height: 56rpx;
        margin: 50rpx 0;
				overflow: hidden;
				text-overflow: ellipsis;
				display: inline-block;
				white-space: nowrap;
    }
    .image {
        width: 398rpx;
        height: 398rpx;
        background: #FFFFFF;
        border-radius: 16rpx;
        opacity: 1;
        border: 2rpx solid #606266;
        padding: 10rpx;
        image {
            width: 398rpx;
            height: 398rpx;
        }
    }
}
.u-list-item:first-child{
	.item{
		margin-top:32rpx;
	}
}
</style>
